package ioProcessorTest;

import ioProcessor.OutputProcessor;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import junit.framework.TestCase;
import smallTools.SimpleTime;
import entities.Section;

public class Test_OutputProcessor extends TestCase {
	public void setUp() {
	}
	
	public void testProcess() throws IOException, FileNotFoundException{
		new Section("CS3343_c01",80,2,"Bush");
		new Section("CS3343_c02",80,2,"Mike");
		//section get
		Section t1=Section.getSectionById("CS3343_c01");

		t1.setSectionRoom("LT02");
		//set duration
		SimpleTime stt=new SimpleTime("MON",9,30);
		t1.setSectionStartTime(stt);
		
		OutputProcessor.process();
		
		FileInputStream outputFile=null;
		//try {
			outputFile = new FileInputStream("Timetable.txt");
		//}
		
		assertNotNull(outputFile);
		DataInputStream outputData = new DataInputStream(outputFile);
		BufferedReader courseReader = new BufferedReader(new InputStreamReader(outputData));
		
		String cInput = "";
		//try 
		//{	
		cInput = courseReader.readLine();
		while(cInput.length()==0)
		{
			cInput = courseReader.readLine();
		}
		assertEquals("CS3343_c01 80 Sun 09:30 Sun 11:30 LT02 Bush", cInput);
		cInput = courseReader.readLine();
		while(cInput.length()==0)
		{
			cInput = courseReader.readLine();
		}
		assertEquals("CS3343_c02 80 Unspecified Time Slot and Room Mike", cInput);
		//}
		/*catch(IOException e)
		{
			System.out.println("Exception while reading the file " + e);
		}
		*/
	}
	
	public void tearDown() {
		Section.clear();
	}
}
